package cn.iocoder.yudao.module.system.controller.admin.goal;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.controller.admin.goal.vo.StudentMajorGroupGoalCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.goal.vo.StudentMajorGroupGoalRespVO;
import cn.iocoder.yudao.module.system.dal.dataobject.goal.StudentMajorGroupGoalDO;
import cn.iocoder.yudao.module.system.service.goal.StudentMajorGroupGoalService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;

@Tag(name = "管理后台 - 学生目标专业组")
@RestController
@RequestMapping("/system/student/goal/major-group")
@Validated
public class StudentMajorGroupGoalController {

    @Resource
    private StudentMajorGroupGoalService studentMajorGroupGoalService;

    @PostMapping("/create")
    @Operation(summary = "创建学生目标专业组")
    public CommonResult<Long> createMajorGroupGoal(@Valid @RequestBody StudentMajorGroupGoalCreateReqVO createReqVO) {
        return success(studentMajorGroupGoalService.createMajorGroupGoal(createReqVO, createReqVO.getUserId()));
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除学生目标专业组")
    @Parameters({
        @Parameter(name = "id", description = "编号", required = true),
        @Parameter(name = "userId", description = "学生ID", required = true)
    })
    public CommonResult<Boolean> deleteMajorGroupGoal(@RequestParam("id") Long id, @RequestParam("userId") Long userId) {
        studentMajorGroupGoalService.deleteMajorGroupGoal(id, userId);
        return success(true);
    }

    @PutMapping("/update-sort")
    @Operation(summary = "更新学生目标专业组排序")
    @Parameters({
            @Parameter(name = "id", description = "编号", required = true),
            @Parameter(name = "sort", description = "排序值", required = true),
            @Parameter(name = "userId", description = "学生ID", required = true)
    })
    public CommonResult<Boolean> updateMajorGroupGoalSort(@RequestParam("id") Long id, @RequestParam("sort") Integer sort, @RequestParam("userId") Long userId) {
        studentMajorGroupGoalService.updateMajorGroupGoalSort(id, sort, userId);
        return success(true);
    }

    @GetMapping("/list")
    @Operation(summary = "获得学生目标专业组列表")
    @Parameter(name = "userId", description = "学生ID", required = true)
    public CommonResult<List<StudentMajorGroupGoalRespVO>> getMajorGroupGoalList(@RequestParam("userId") Long userId) {
        List<StudentMajorGroupGoalDO> list = studentMajorGroupGoalService.getMajorGroupGoalList(userId);
        return success(BeanUtils.toBean(list, StudentMajorGroupGoalRespVO.class));
    }
}
